/**
 * @JsonBusiMixedEncoder.java  COPYRIGHT xiaojian
 * 
 * Created on 2017年7月20日 下午7:40:38
 */
package xj.toolkit.access.busi.codec;

import xj.toolkit.util.MutableIdentifyable;
import xj.toolkit.bean.json.annotation.JSONMessage;

/**
 * @author <a href="mailto:cxj2000@gmail.com">xiaojian.cao</a>
 *
 */
public abstract class JsonBusiMixedEncoder extends BusiMixedEncoder {

	@Override
	protected int getMsgCode(MutableIdentifyable msg) {
		JSONMessage jm = msg.getClass().getAnnotation(JSONMessage.class);
		if (jm == null) {
			throw new RuntimeException(
					"invalid json message, missing @JSONMessage.");
		}

		return jm.messageCode();
	}

	@Override
	protected abstract byte[] build(MutableIdentifyable msg);

}
